package com.craterhill.java.ccp.dao.utils;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowMapper;

import com.craterhill.java.ccp.common.beans.CCPBeans;

public abstract class CCPResultSetExtractor<T extends CCPBeans> implements ResultSetExtractor<T>, RowMapper<T> {

	@Override
	public final T extractData(ResultSet resultSet) throws SQLException, DataAccessException {
		if (resultSet.next())
			return extractResultSetData(resultSet);
		return null;
	}

	@Override
	public final T mapRow(ResultSet resultSet, int rowNum) throws SQLException {
		return extractResultSetData(resultSet);
	}

	protected abstract T extractResultSetData(ResultSet resultSet) throws SQLException;
}
